<?php
    class sscls_UserModel extends sscls_Model
    {   

        function __construct()
        {
            parent::__construct();
        }
        //check username and password in database
        function checkLogin($username, $password)
        {        
			$sql="select * from users where username='".$username."' and password='".md5($password)."' limit 1";
			$result=$this->_db->loadObject($sql);
			//var_dump($result);die;
			if(isset($result->id)&&$result->block==0)
			{
				$session=ss_Main::getSession();
				ini_set('session.cookie_lifetime',1000);
				$session->set('user',$result);
				return true;
			}
          //return false when login success
            return false;
        }
		function getUser()
	   {
			return $this->_db->loadObjectList('select * from users');
	   }
	   
	    function store1($data,$tablename)
	   {
			$result=$this->store($data,$tablename);
			return $result;
	   }
	   
	   function getUserById($id)
	   {
			$query='select * from users where id='.(int)$id;
			return $this->_db->loadObject($query);
	   }
	   	   
	   function remove($ids)
	   {
		if(is_array($ids))
			$sql='delete from users where id in ('.implode(',',$ids).')';
		else
			$sql='delete from users where id ='.(int)$ids;
		return $this->_db->query($sql);
	   }
	   
	   function checkemail($email)
	   {
			$row=$this->_db->loadObject('select * from users where email="'.$email.'"');
			return isset($row->id)?true:false;
	   }
	   
	   function checkusername($username)
	   {
			$row=$this->_db->loadObject('select * from users where username="'.$username.'"');
			return isset($row->id)?true:false;
	   }
    }
?>
